import re
import os
import logging
from logging.handlers import TimedRotatingFileHandler
from logging.handlers import RotatingFileHandler

class logHelper():
    logger = None
    
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(level = logging.DEBUG)
        path = '../logs'
        if os.path.exists(path) == False:
            os.mkdir(path)
        logs_path = os.path.join(path, 'log')
        handler = TimedRotatingFileHandler(filename=logs_path, when='MIDNIGHT', interval=1, backupCount=7)
        handler.suffix = '%Y-%m-%d.log'
        handler.extMatch = re.compile(r'^\d{4}-\d{2}-\d{2}.log$')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        console = logging.StreamHandler()
        console.setLevel(logging.DEBUG)
        self.logger.addHandler(handler)
        self.logger.addHandler(console)

